import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { setupRouterGuard } from "./guard";

const routes: Array<RouteRecordRaw> = [
	{
		path: "/",
		name: "Layout",
		component: () => import("@/layout/index.vue"),
		redirect: "/dashboard",
		children: [
			{
				path: "dashboard",
				name: "Dashboard",
				component: () => import("@/views/demo/update-dialog.vue"),
				meta: {
					requiresAuth: true,
					title: "首页",
					icon: "House",
				},
			},
			{
				path: "user",
				name: "User",
				redirect: "/user/list",
				meta: {
					requiresAuth: true,
					title: "用户管理",
					icon: "User",
				},
				children: [
					{
						path: "list",
						name: "UserList",
						component: () => import("@/views/user/list/index.vue"),
						meta: {
							requiresAuth: true,
							title: "用户列表",
							icon: "List",
						},
					},
				],
			},
		],
	},
	{
		path: "/sign",
		name: "Sign",
		redirect: "/sign/login",
		children: [
			{
				path: "login",
				name: "Login",
				component: () => import("@/views/sign/login/index.vue"),
				meta: {
					title: "Sign In",
				},
			},
			{
				path: "register",
				name: "Register",
				component: () => import("@/views/sign/register/index.vue"),
				meta: {
					title: "Sign Up",
				},
			},
			{
				path: "forgot-password",
				name: "ForgotPassword",
				component: () => import("@/views/sign/forgot-password/index.vue"),
				meta: {
					title: "Reset Password",
				},
			},
		],
	},
];

const router = createRouter({
	history: createWebHistory(),
	routes,
});

// 设置路由守卫
setupRouterGuard(router);

export default router;
